package com.ruoyi.project.mobile.jiaqin;

import com.ruoyi.common.utils.R;
import com.ruoyi.project.jiaqin.advert.domain.JiaqinAdvert;
import com.ruoyi.project.jiaqin.advert.service.IJiaqinAdvertService;
import com.ruoyi.project.jiaqin.advertising.service.IAdvertisingService;
import com.ruoyi.project.jiaqin.company.domain.Company;
import com.ruoyi.project.jiaqin.company.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/api/jq/advert")
public class ApiAdvertController {

    @Autowired
    private IAdvertisingService iAdvertisingService;
    @Autowired
    private IJiaqinAdvertService iJiaqinAdvertService;
    @Autowired
    private ICompanyService companyService;
    /**
     * 根据投放位置编号获取广告列表
     */
    @GetMapping("/getAdvertising")
    public R getAdvertising(Integer putAddr){
        HashMap<String,Object> map = new HashMap<>();
        List<JiaqinAdvert> list = iJiaqinAdvertService.selectJiaqinAdvertByPutAddr(putAddr);
        for (JiaqinAdvert JA : list) {
            if (JA.getType() == 0) {
                Company companyById = companyService.selectCompanyById(JA.getParamCompany());
                if (companyById != null) {
                    JA.setParamCompany(companyById.getMemberId());
                }
            }
        }
        map.put("data",list);
        return R.ok(map);
    }


    /**
     * 根据广告ID获取广告详情
     */
    @GetMapping("/getAdvertById")
    public R getAdvertById(String id){
        HashMap<String,Object> map = new HashMap<>();
        JiaqinAdvert jiaqinAdvert = iJiaqinAdvertService.selectJiaqinAdvertById(id);
        map.put("data",jiaqinAdvert);
        return R.ok(map);
    }
}
